/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wf.model;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import java.util.Date;
import wf.units.DatabaseUnit;

/**
 *
 * @author bennyl
 */
@DatabaseTable(tableName = "scheduling")
public class Schedule {

    @DatabaseField(canBeNull = false)
    int valveId;
    @DatabaseField(canBeNull = false)
    Date dayTime;
    @DatabaseField(canBeNull = false)
    int periodMinute;
    @DatabaseField(generatedId = true)
    int id;

    public Schedule() {
    }

    public Schedule(int valveId, Date dayTime, int periodMinute) {
        this.dayTime = dayTime;
        this.periodMinute = periodMinute;
        this.valveId = valveId;
        this.id = -1;
    }

    public void setDayTime(Date dayTime) {
        this.dayTime = dayTime;
    }

    public Date getDayTime() {
        return dayTime;
    }

    public int getPeriodMinute() {
        return periodMinute;
    }

    @Override
    public String toString() {
        final Valve valve = DatabaseUnit.UNIT.selectItem(Valve.class, valveId);
        PLC plc = null;
        if (valve != null) {
            plc = DatabaseUnit.UNIT.selectItem(PLC.class, valve.getPlcIp());
        }

        if (plc == null || valve == null) {
            return "CURRAPTED SCHEDULING!";
        }

        return "Activating Valve '" + valve.getName() + "@" + plc.getName() + "' at " + dayTime + " for " + periodMinute + " minutes.";
    }

    public int getValveId() {
        return valveId;
    }

    public void setValveId(int valveId) {
        this.valveId = valveId;
    }
}
